package com.liuguang.framework.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Environment;
import android.os.StatFs;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import com.liuguang.framework.base.BaseApplication;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class AppUtils {
    private static BaseApplication application;
    private static String sDeviceAbi;
    private static String sRuntimeAbi;

    public static class MemoryInfo {
        int memorySize;
        int pid;
        String processName;
        int uid;
    }

    public static void init(BaseApplication baseApplication) {
        application = baseApplication;
    }

    public static BaseApplication getApplication() {
        return application;
    }

    public static String getDisplayMetrics() {
        new DisplayMetrics();
        DisplayMetrics displayMetrics = getApplication().getResources().getDisplayMetrics();
        StringBuilder sb = new StringBuilder();
        sb.append(displayMetrics.widthPixels);
        sb.append("*");
        sb.append(displayMetrics.heightPixels);
        return sb.toString();
    }

    public static int getScreenWidth() {
        try {
            new DisplayMetrics();
            return getApplication().getResources().getDisplayMetrics().widthPixels;
        } catch (Exception unused) {
            return 0;
        }
    }

    public static int getScreenHeight() {
        try {
            new DisplayMetrics();
            return getApplication().getResources().getDisplayMetrics().heightPixels;
        } catch (Exception unused) {
            return 0;
        }
    }

    @SuppressLint({"MissingPermission"})
    public static String getIMEI() {
        try {
            return ((TelephonyManager) getApplication().getSystemService("phone")).getDeviceId();
        } catch (Exception unused) {
            return "";
        }
    }

    public static String getVersion() {
        return VERSION.RELEASE;
    }

    public static int getVersionSDK() {
        return VERSION.SDK_INT;
    }

    public static String getModel() {
        return Build.MODEL;
    }

    public static int getAppVersionCode() {
        try {
            return application.getPackageManager().getPackageInfo(application.getPackageName(), 0).versionCode;
        } catch (NameNotFoundException e) {
            e.printStackTrace(System.err);
            return -1;
        }
    }

    public static String getAppVersion() {
        try {
            return "3.1.0";
//            return application.getPackageManager().getPackageInfo(application.getPackageName(), 0).versionName;
        } catch (Exception e) {
            e.printStackTrace(System.err);
            return "";
        }
    }

    public static int getRemainMemory() {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getPath());
        return ((statFs.getAvailableBlocks() * statFs.getBlockSize()) / 1024) / 1024;
    }

    public static int dip2px(float f) {
        return (int) ((f * getApplication().getResources().getDisplayMetrics().density) + 0.5f);
    }

    public static int px2dip(float f) {
        return (int) ((f / getApplication().getResources().getDisplayMetrics().density) + 0.5f);
    }

    private static boolean is64bitDevice() {
        String deviceAbi = getDeviceAbi();
        return deviceAbi.equals("arm64-v8a") || deviceAbi.equals("x86_64");
    }

    private static String getDeviceAbi() {
        if (sDeviceAbi == null) {
            try {
                if (VERSION.SDK_INT >= 21) {
                    sDeviceAbi = Build.SUPPORTED_ABIS[0].toLowerCase();
                } else {
                    sDeviceAbi = getsDeviceAbi();
                }
            } catch (NoSuchFieldError unused) {
                sDeviceAbi = getsDeviceAbi();
            }
        }
        return sDeviceAbi;
    }

    private static String getsDeviceAbi() {
        try {
            InputStreamReader inputStreamReader = new InputStreamReader(Runtime.getRuntime().exec("getprop ro.product.cpu.abi").getInputStream());
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String lowerCase = bufferedReader.readLine().toLowerCase();
            bufferedReader.close();
            inputStreamReader.close();
            return lowerCase;
        } catch (IOException unused) {
            throw new RuntimeException("Can not detect device's ABI");
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:24:0x0050, code lost:
        r6 = 65535;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:25:0x0051, code lost:
        switch(r6) {
            case 0: goto L_0x0069;
            case 1: goto L_0x0069;
            case 2: goto L_0x0063;
            case 3: goto L_0x005d;
            case 4: goto L_0x0057;
            default: goto L_0x0054;
        };
     */
    /* JADX WARNING: Code restructure failed: missing block: B:27:0x0057, code lost:
        sRuntimeAbi = "x86_64";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:28:0x005d, code lost:
        sRuntimeAbi = "x86";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:29:0x0063, code lost:
        sRuntimeAbi = "arm64-v8a";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:30:0x0069, code lost:
        sRuntimeAbi = "armeabi-v7a";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:31:0x006f, code lost:
        sRuntimeAbi = android.support.v4.os.EnvironmentCompat.MEDIA_UNKNOWN;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:47:0x00b9, code lost:
        if (r6.equals("ia32") != false) goto L_0x0117;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:67:0x00fe, code lost:
        if (r6.equals("aarch64") != false) goto L_0x0109;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:69:0x0107, code lost:
        if (r6.equals("armv8l") != false) goto L_0x0109;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:70:0x0109, code lost:
        r0 = 9;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:74:0x0116, code lost:
        r0 = 65535;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:75:0x0117, code lost:
        switch(r0) {
            case 0: goto L_0x0144;
            case 1: goto L_0x0144;
            case 2: goto L_0x0144;
            case 3: goto L_0x0144;
            case 4: goto L_0x0134;
            case 5: goto L_0x0134;
            case 6: goto L_0x012f;
            case 7: goto L_0x012f;
            case 8: goto L_0x012f;
            case 9: goto L_0x011f;
            case 10: goto L_0x011f;
            case 11: goto L_0x011f;
            default: goto L_0x011a;
        };
     */
    /* JADX WARNING: Code restructure failed: missing block: B:76:0x011a, code lost:
        sRuntimeAbi = android.support.v4.os.EnvironmentCompat.MEDIA_UNKNOWN;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:78:0x0123, code lost:
        if (is64bitDevice() == false) goto L_0x012a;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:79:0x0125, code lost:
        sRuntimeAbi = "arm64-v8a";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:80:0x012a, code lost:
        sRuntimeAbi = "armeabi-v7a";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:81:0x012f, code lost:
        sRuntimeAbi = "armeabi-v7a";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:83:0x0138, code lost:
        if (is64bitDevice() == false) goto L_0x013f;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:84:0x013a, code lost:
        sRuntimeAbi = "x86_64";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:85:0x013f, code lost:
        sRuntimeAbi = "x86";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:86:0x0144, code lost:
        sRuntimeAbi = "x86";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:88:0x0150, code lost:
        if (sRuntimeAbi.equals("armeabi-v7a") == false) goto L_0x015d;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:90:0x0156, code lost:
        if (isIaDevice() == false) goto L_0x0171;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:91:0x0158, code lost:
        sRuntimeAbi = "x86";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:93:0x0165, code lost:
        if (sRuntimeAbi.equals("arm64-v8a") == false) goto L_0x0171;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:95:0x016b, code lost:
        if (isIaDevice() == false) goto L_0x0171;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:96:0x016d, code lost:
        sRuntimeAbi = "x86_64";
     */
    /* JADX WARNING: Code restructure failed: missing block: B:97:0x0171, code lost:
        r1 = new java.lang.StringBuilder();
        r1.append("Runtime ABI: ");
        r1.append(sRuntimeAbi);
        android.util.Log.d("XWalkLib", r1.toString());
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static java.lang.String getRuntimeAbi() {
        /*
            java.lang.String r0 = sRuntimeAbi
            if (r0 != 0) goto L_0x0189
            r0 = 3
            r1 = 1
            r2 = 2
            r3 = 0
            r4 = 4
            r5 = -1
            int r6 = android.os.Build.VERSION.SDK_INT     // Catch:{ NoSuchFieldError -> 0x0079 }
            r7 = 21
            if (r6 >= r7) goto L_0x0073
            java.lang.String r6 = android.os.Build.CPU_ABI     // Catch:{ NoSuchFieldError -> 0x0079 }
            java.lang.String r6 = r6.toLowerCase()     // Catch:{ NoSuchFieldError -> 0x0079 }
            int r7 = r6.hashCode()     // Catch:{ NoSuchFieldError -> 0x0079 }
            switch(r7) {
                case -806050265: goto L_0x0046;
                case -738963905: goto L_0x003c;
                case 117110: goto L_0x0032;
                case 145444210: goto L_0x0028;
                case 1431565292: goto L_0x001e;
                default: goto L_0x001d;
            }     // Catch:{ NoSuchFieldError -> 0x0079 }
        L_0x001d:
            goto L_0x0050
        L_0x001e:
            java.lang.String r7 = "arm64-v8a"
            boolean r6 = r6.equals(r7)     // Catch:{ NoSuchFieldError -> 0x0079 }
            if (r6 == 0) goto L_0x0050
            r6 = 2
            goto L_0x0051
        L_0x0028:
            java.lang.String r7 = "armeabi-v7a"
            boolean r6 = r6.equals(r7)     // Catch:{ NoSuchFieldError -> 0x0079 }
            if (r6 == 0) goto L_0x0050
            r6 = 1
            goto L_0x0051
        L_0x0032:
            java.lang.String r7 = "x86"
            boolean r6 = r6.equals(r7)     // Catch:{ NoSuchFieldError -> 0x0079 }
            if (r6 == 0) goto L_0x0050
            r6 = 3
            goto L_0x0051
        L_0x003c:
            java.lang.String r7 = "armeabi"
            boolean r6 = r6.equals(r7)     // Catch:{ NoSuchFieldError -> 0x0079 }
            if (r6 == 0) goto L_0x0050
            r6 = 0
            goto L_0x0051
        L_0x0046:
            java.lang.String r7 = "x86_64"
            boolean r6 = r6.equals(r7)     // Catch:{ NoSuchFieldError -> 0x0079 }
            if (r6 == 0) goto L_0x0050
            r6 = 4
            goto L_0x0051
        L_0x0050:
            r6 = -1
        L_0x0051:
            switch(r6) {
                case 0: goto L_0x0069;
                case 1: goto L_0x0069;
                case 2: goto L_0x0063;
                case 3: goto L_0x005d;
                case 4: goto L_0x0057;
                default: goto L_0x0054;
            }     // Catch:{ NoSuchFieldError -> 0x0079 }
        L_0x0054:
            java.lang.String r6 = "unknown"
            goto L_0x006f
        L_0x0057:
            java.lang.String r6 = "x86_64"
            sRuntimeAbi = r6     // Catch:{ NoSuchFieldError -> 0x0079 }
            goto L_0x0148
        L_0x005d:
            java.lang.String r6 = "x86"
            sRuntimeAbi = r6     // Catch:{ NoSuchFieldError -> 0x0079 }
            goto L_0x0148
        L_0x0063:
            java.lang.String r6 = "arm64-v8a"
            sRuntimeAbi = r6     // Catch:{ NoSuchFieldError -> 0x0079 }
            goto L_0x0148
        L_0x0069:
            java.lang.String r6 = "armeabi-v7a"
            sRuntimeAbi = r6     // Catch:{ NoSuchFieldError -> 0x0079 }
            goto L_0x0148
        L_0x006f:
            sRuntimeAbi = r6     // Catch:{ NoSuchFieldError -> 0x0079 }
            goto L_0x0148
        L_0x0073:
            java.lang.NoSuchFieldError r6 = new java.lang.NoSuchFieldError     // Catch:{ NoSuchFieldError -> 0x0079 }
            r6.<init>()     // Catch:{ NoSuchFieldError -> 0x0079 }
            throw r6     // Catch:{ NoSuchFieldError -> 0x0079 }
        L_0x0079:
            java.lang.String r6 = "os.arch"
            java.lang.String r6 = java.lang.System.getProperty(r6)
            java.lang.String r6 = r6.toLowerCase()
            int r7 = r6.hashCode()
            r8 = 9
            switch(r7) {
                case -1409295825: goto L_0x010c;
                case -1409295794: goto L_0x0101;
                case -1221096139: goto L_0x00f8;
                case -806050265: goto L_0x00ee;
                case -738963905: goto L_0x00e4;
                case 117046: goto L_0x00da;
                case 117110: goto L_0x00d0;
                case 3178856: goto L_0x00c6;
                case 3181739: goto L_0x00bc;
                case 3222903: goto L_0x00b3;
                case 93084186: goto L_0x00a7;
                case 93086174: goto L_0x009b;
                case 145444210: goto L_0x008f;
                default: goto L_0x008d;
            }
        L_0x008d:
            goto L_0x0116
        L_0x008f:
            java.lang.String r0 = "armeabi-v7a"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 8
            goto L_0x0117
        L_0x009b:
            java.lang.String r0 = "armv8"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 10
            goto L_0x0117
        L_0x00a7:
            java.lang.String r0 = "arm64"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 11
            goto L_0x0117
        L_0x00b3:
            java.lang.String r1 = "ia32"
            boolean r1 = r6.equals(r1)
            if (r1 == 0) goto L_0x0116
            goto L_0x0117
        L_0x00bc:
            java.lang.String r0 = "i686"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 1
            goto L_0x0117
        L_0x00c6:
            java.lang.String r0 = "i386"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 2
            goto L_0x0117
        L_0x00d0:
            java.lang.String r0 = "x86"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 0
            goto L_0x0117
        L_0x00da:
            java.lang.String r0 = "x64"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 4
            goto L_0x0117
        L_0x00e4:
            java.lang.String r0 = "armeabi"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 7
            goto L_0x0117
        L_0x00ee:
            java.lang.String r0 = "x86_64"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 5
            goto L_0x0117
        L_0x00f8:
            java.lang.String r0 = "aarch64"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            goto L_0x0109
        L_0x0101:
            java.lang.String r0 = "armv8l"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
        L_0x0109:
            r0 = 9
            goto L_0x0117
        L_0x010c:
            java.lang.String r0 = "armv7l"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x0116
            r0 = 6
            goto L_0x0117
        L_0x0116:
            r0 = -1
        L_0x0117:
            switch(r0) {
                case 0: goto L_0x0144;
                case 1: goto L_0x0144;
                case 2: goto L_0x0144;
                case 3: goto L_0x0144;
                case 4: goto L_0x0134;
                case 5: goto L_0x0134;
                case 6: goto L_0x012f;
                case 7: goto L_0x012f;
                case 8: goto L_0x012f;
                case 9: goto L_0x011f;
                case 10: goto L_0x011f;
                case 11: goto L_0x011f;
                default: goto L_0x011a;
            }
        L_0x011a:
            java.lang.String r0 = "unknown"
            sRuntimeAbi = r0
            goto L_0x0148
        L_0x011f:
            boolean r0 = is64bitDevice()
            if (r0 == 0) goto L_0x012a
            java.lang.String r0 = "arm64-v8a"
            sRuntimeAbi = r0
            goto L_0x0148
        L_0x012a:
            java.lang.String r0 = "armeabi-v7a"
            sRuntimeAbi = r0
            goto L_0x0148
        L_0x012f:
            java.lang.String r0 = "armeabi-v7a"
            sRuntimeAbi = r0
            goto L_0x0148
        L_0x0134:
            boolean r0 = is64bitDevice()
            if (r0 == 0) goto L_0x013f
            java.lang.String r0 = "x86_64"
            sRuntimeAbi = r0
            goto L_0x0148
        L_0x013f:
            java.lang.String r0 = "x86"
            sRuntimeAbi = r0
            goto L_0x0148
        L_0x0144:
            java.lang.String r0 = "x86"
            sRuntimeAbi = r0
        L_0x0148:
            java.lang.String r0 = sRuntimeAbi
            java.lang.String r1 = "armeabi-v7a"
            boolean r0 = r0.equals(r1)
            if (r0 == 0) goto L_0x015d
            boolean r0 = isIaDevice()
            if (r0 == 0) goto L_0x0171
            java.lang.String r0 = "x86"
            sRuntimeAbi = r0
            goto L_0x0171
        L_0x015d:
            java.lang.String r0 = sRuntimeAbi
            java.lang.String r1 = "arm64-v8a"
            boolean r0 = r0.equals(r1)
            if (r0 == 0) goto L_0x0171
            boolean r0 = isIaDevice()
            if (r0 == 0) goto L_0x0171
            java.lang.String r0 = "x86_64"
            sRuntimeAbi = r0
        L_0x0171:
            java.lang.String r0 = "XWalkLib"
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r1.<init>()
            java.lang.String r2 = "Runtime ABI: "
            r1.append(r2)
            java.lang.String r2 = sRuntimeAbi
            r1.append(r2)
            java.lang.String r1 = r1.toString()
            android.util.Log.d(r0, r1)
        L_0x0189:
            java.lang.String r0 = sRuntimeAbi
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.liuguang.framework.utils.AppUtils.getRuntimeAbi():java.lang.String");
    }

    private static boolean isIaDevice() {
        String deviceAbi = getDeviceAbi();
        boolean z = false;
        if (deviceAbi == null) {
            return false;
        }
        if (deviceAbi.equals("x86") || deviceAbi.equals("x86_64")) {
            z = true;
        }
        return z;
    }

    public static int getCurrentMenmoryInfo() {
        for (MemoryInfo memoryInfo : getMemory(getApplication())) {
            if (getApplication().getPackageName().equals(memoryInfo.processName)) {
                return memoryInfo.memorySize;
            }
        }
        return 0;
    }

    public static List<MemoryInfo> getMemory(Context context) {
        ArrayList arrayList = new ArrayList();
        ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
        for (RunningAppProcessInfo runningAppProcessInfo : activityManager.getRunningAppProcesses()) {
            MemoryInfo memoryInfo = new MemoryInfo();
            memoryInfo.pid = runningAppProcessInfo.pid;
            memoryInfo.uid = runningAppProcessInfo.uid;
            memoryInfo.processName = runningAppProcessInfo.processName;
            memoryInfo.memorySize = activityManager.getProcessMemoryInfo(new int[]{memoryInfo.pid})[0].dalvikPrivateDirty;
            arrayList.add(memoryInfo);
        }
        return arrayList;
    }

    public static long getTotalMemory() {
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/meminfo"), 8192);
            String readLine = bufferedReader.readLine();
            String[] split = readLine.split("\\s+");
            for (String str : split) {
                StringBuilder sb = new StringBuilder();
                sb.append(str);
                sb.append("\t");
                Log.i(readLine, sb.toString());
            }
            long intValue = (long) (Integer.valueOf(split[1]).intValue() / 1000);
            bufferedReader.close();
            return intValue;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static boolean isPad(Activity activity) {
        return isMoreThan6Inch(activity) && isScreenSizeLarge(activity);
    }

    private static boolean isMoreThan6Inch(Activity activity) {
        Display defaultDisplay = ((WindowManager) activity.getSystemService("window")).getDefaultDisplay();
        defaultDisplay.getWidth();
        defaultDisplay.getHeight();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        defaultDisplay.getMetrics(displayMetrics);
        return Math.sqrt(Math.pow((double) (((float) displayMetrics.widthPixels) / displayMetrics.xdpi), 2.0d) + Math.pow((double) (((float) displayMetrics.heightPixels) / displayMetrics.ydpi), 2.0d)) >= 6.0d;
    }

    public static boolean isScreenSizeLarge(Context context) {
        return (context.getResources().getConfiguration().screenLayout & 15) >= 3;
    }
}
